﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace IssueIT.Core.Domain
{
    public class ProjectUriValidator
    {
        public bool IsAllowed { get; private set; }
        public string AllowedUri { get; private set; }
        
        private string _projectUri;
        

        public ProjectUriValidator(string projectUri)
        {
            _projectUri = projectUri;

            AllowedUri = GenerateAllowedUri();
         
            IsAllowed = AllowedUri.Equals(_projectUri);
        }

        private string GenerateAllowedUri()
        {
            string str = _projectUri.ToLower();

            // invalid chars, make into spaces 
            str = Regex.Replace(str, @"[^a-z0-9s-]", "");
            // convert multiple spaces/hyphens into one space      
            str = Regex.Replace(str, @"[s-]+", " ").Trim();
            // hyphens 
            str = Regex.Replace(str, @"s", "-");

            return str;
            
        }
    }
}
